'''
Created on Nov 21, 2009

@author: anch
'''
import unittest
import __builtin__
import interface.ConsoleAgent as itfc
import gamephase.humanVsHuman
import global_controller
import gamemodel.player as mPlayer
import gamemodel.state as mState
import ai.human as mAI

class Test(unittest.TestCase):
	stored_state = None
	
	def setUp(self):
		game_phase = gamephase.humanVsHuman.HumanVsHuman()
		player0 = mPlayer.CheckerPlayer("Diablo")
		player0.attachAI(mAI.AIHuman)
		player1 = mPlayer.CheckerPlayer("Bhaal")
		player1.attachAI(mAI.AIHuman)
		
		game_phase.state = \
			mState.CheckerState.constructNew(player0, player1)
		__builtin__.G.game_phase = game_phase
		
		Test.stored_state = game_phase.state
		pass
	
	def tearDown(self):
		del __builtin__.G.game_phase
		del __builtin__.G
		pass

	def testRetrieveCoordinates(self):
		input = "e,10"
		coord = itfc.ConsoleDescriptor.retrieveCoordinate(input)
		self.assertEqual((4,0), coord[0])
		
		input = "10,f"
		coord = itfc.ConsoleDescriptor.retrieveCoordinate(input)
		self.assertEqual((5,0), coord[0])
		
		input = "5,e"
		coord = itfc.ConsoleDescriptor.retrieveCoordinate(input)
		self.assertEqual((4,5), coord[0])
		
		input = "e,5"
		coord = itfc.ConsoleDescriptor.retrieveCoordinate(input)
		self.assertEqual((4,5), coord[0])
		
		Test.stored_state.switchPlayer()
		coord = itfc.ConsoleDescriptor.retrieveCoordinate(input)
		self.assertEqual((5,4), coord[0])
		pass


if __name__ == "__main__":
	#import sys;sys.argv = ['', 'Test.testRetrieveCoordinates']
	unittest.main()